package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.pojo.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐业务控制层
 *
 * @Author: Zhy
 * @Date: 2025-01-21 下午6:15
 * @Version: 1.0
 */
@Slf4j
@Api(tags = "套餐管理")
@RestController
@RequestMapping("/admin/setmeal")
@RequiredArgsConstructor
public class SetmealController {

	private final SetmealService setmealService;

	/**
	 * 添加套餐
	 *
	 * @return:
	 * @param:
	 */
	@PostMapping
	@ApiOperation("添加套餐")
	public Result<String> addSetmeal(@RequestBody SetmealDTO setmealDTO) {
		log.info("添加套餐，setmealDTO:{}", setmealDTO);

		return setmealService.addSetmeal(setmealDTO);
	}

	/**
	 * 套餐分页查询
	 *
	 * @return:
	 * @param:
	 */
	@GetMapping("/page")
	@ApiOperation("套餐分页查询")
	public Result<PageResult<Setmeal>> pageSetmeal(SetmealPageQueryDTO setmealPageQueryDTO) {
		log.info("套餐分页查询，setmealPageQueryDTO:{}", setmealPageQueryDTO);

		return setmealService.pageQuerySetmeal(setmealPageQueryDTO);
	}

	/**
	 * 根据 id 查询套餐
	 *
	 * @return:
	 * @param:
	 */
	@GetMapping("/{setmealId}")
	@ApiOperation("根据 id 查询套餐")
	public Result<SetmealVO> getSetmealById(@PathVariable("setmealId") Long setmealId) {
		log.info("根据 id 查询套餐，setmealId:{}", setmealId);

		return setmealService.getSetmealById(setmealId);
	}

	/**
	 * 更新套餐信息
	 *
	 * @return:
	 * @param:
	 */
	@PutMapping
	@ApiOperation("修改套餐")
	public Result<String> updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
		log.info("修改套餐，setmealDTO:{}", setmealDTO);

		return setmealService.updateSetmeal(setmealDTO);
	}

	/**
	 * 修改套餐状态
	 *
	 * @return:
	 * @param:
	 */
	@PostMapping("/status/{status}")
	@ApiOperation("修改套餐状态")
	public Result<String> updateSetmealStatus(@PathVariable("status") Integer status, @RequestParam("id") Long id) {
		log.info("修改套餐状态，status:{}, id:{}", status, id);

		return setmealService.updateSetmealStatus(status, id);
	}

	/**
	 * 删除套餐信息
	 *
	 * @return:
	 * @param:
	 */
	@DeleteMapping
	@ApiOperation("删除套餐")
	public Result<String> deleteSetmeal(@RequestParam("ids") List<Long> ids) {
		log.info("删除套餐，ids:{}", ids);

		return setmealService.deleteSetmealByIds(ids);
	}

}
